package com.example.tabbar.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.tabbar.adapter.PrintSelectAdapter
import com.example.tabbar.databinding.FragmentSetPrintBinding
import com.example.tabbar.room.entity.Print


class SetPrintFragment : Fragment() {
    private var binding: FragmentSetPrintBinding? = null
    private var printList: RecyclerView? = null
    private var adapter: PrintSelectAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentSetPrintBinding.inflate(inflater, container, false)
        return binding!!.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        printList = binding?.setPrint
        adapter = PrintSelectAdapter()
        printList?.adapter = adapter

        printList?.layoutManager = GridLayoutManager(requireContext(), 3)

        val list = createPrint()
        adapter?.setItems(list)
    }

    private fun createPrint() : List<Print>{
        val list = listOf(
            // 第一行
            Print(1, "0.1μm"),
            Print(2, "0.3μm"),
            Print(3, "0.5μm"),

            // 第二行
            Print(4, "1.0μm"),
            Print(5, "3.0μm"),
            Print(6, "10.0μm"),

            // 第三行
            Print(7, "Σ"),
            Print(8, "Δ"),
            Print(9, "标准"),

            // 第四行
            Print(10, "等级"),
            Print(11, "状态"),
            Print(12, "95%UCL"),

            // 第五行
            Print(13, "当前模式"),
            Print(14, "温度"),
            Print(15, "湿度"),

            // 第六行
            Print(16, "大气压"),
            Print(17, "采样次数"),
            Print(18, "点位名称"),

            // 第七行
            Print(19, "采样时长"),
            Print(20, "采样流量"),
            Print(21, "开始时间"),

            // 第八行
            Print(22, "结束时间"),
            Print(23, "分组"),
            Print(24, "房间"),

            // 第九行
            Print(25, "校准日期"),
            Print(26, "配方"),
            Print(27, "结果判定"),

            // 第十行
            Print(28, "流量"),
            Print(29, "体积"),
            Print(30, "单位")
        )
        return list
    }

    companion object {

        @JvmStatic
        fun newInstance() =
            SetPrintFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}